﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;
using VIW = CPPEI.ETL.Domain.Views;

namespace CPPEI.ETL.WebApi.CCR
{
    /// <summary>
    /// 获取单条编码转换规则
    /// </summary>
    [CPPEI.WebApi.AuthGetAction("CCR", "Get", "1.0")]
    public class GetSingleAction : BaseAction<GetSingleParams, GetSingleResult>
    {
        protected override ActionResult<GetSingleResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            GetSingleParams opParams)
        {
            SER.CodeConversionRuleService service = new SER.CodeConversionRuleService();
            ServiceResult<VIW.VCodeConversionRule> serResult = service.GetSingle(opParams.Id);
            if (serResult.IsSuccess)
            {
                GetSingleResult result = new GetSingleResult();
                result.Id = serResult.Data.Id;
                result.DimId = serResult.Data.DimId;
                result.DimCode = serResult.Data.DimCode;
                result.DimName = serResult.Data.DimName;
                result.DimItemId = serResult.Data.DimItemId;
                result.DimItemCode = serResult.Data.DimItemCode;
                result.DimItemName = serResult.Data.DimItemName;
                result.RawCodes = serResult.Data.RawCodes;
                return new ActionResult<GetSingleResult>(result);
            }
            else
            {
                return new ActionResult<GetSingleResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class GetSingleParams
    {
        public Guid Id { get; set; }
    }

    public class GetSingleResult
    {
        public Guid Id { get; set; }

        /// <summary>
        /// 对应的维度id
        /// </summary>
        public Guid DimId { get; set; }

        public string DimCode { get; set; }

        public string DimName { get; set; }

        /// <summary>
        /// 对应维度项id
        /// </summary>
        public Guid DimItemId { get; set; }

        public string DimItemCode { get; set; }

        public string DimItemName { get; set; }

        /// <summary>
        /// 原始编码
        /// </summary>
        public string RawCodes { get; set; }
    }
}
